﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace TopShooter.Drawing
{
	public class Shapes
	{
		static public Shapes Instance { get; private set; }

		private Texture2D _whiteDot;

		public SpriteBatch Sprites;

		public Shapes()
		{
			Instance = this;
			Sprites = Game.Instance.SpriteBatch;
			_whiteDot = new Texture2D(Game.Instance.Drawer.GraphicsDevice, 1, 1);
			_whiteDot.SetData(new Color[] { Color.White });
		}

		public void DrawLine(Vector2 start, Vector2 end, Color color, int width)
		{
			float length = (end - start).Length();
			float rotation = (float)Math.Atan2(end.Y - start.Y, end.X - start.X);
			Sprites.Draw(_whiteDot, start, null, color, rotation, Vector2.Zero, new Vector2(length, width), SpriteEffects.None, 0);
		}

		public void DrawRectangle(Rectangle rectangle, Color color, int width)
		{
			Sprites.Draw(_whiteDot, new Rectangle(rectangle.Left, rectangle.Top, rectangle.Width, width), color);
			Sprites.Draw(_whiteDot, new Rectangle(rectangle.Left, rectangle.Bottom, rectangle.Width, width), color);
			Sprites.Draw(_whiteDot, new Rectangle(rectangle.Left, rectangle.Top, width, rectangle.Height), color);
			Sprites.Draw(_whiteDot, new Rectangle(rectangle.Right, rectangle.Top, width, rectangle.Height + 1), color);
		}

		public void FillRectangle(Rectangle rectangle, Color color)
		{
			Sprites.Draw(_whiteDot, rectangle, color);
		}
	}
}
